<template>
    <div class="box-content">
        <div class="navigation">文件管理/文件列表</div>
        <!--搜索-->
        <div class="mt-3">
            <div>
                <!--<el-input-->
                        <!--class="w-25 mr-5"-->
                        <!--placeholder="文件名称"-->
                        <!--v-model="searchParams.fileName"-->
                        <!--clearable>-->
                <!--</el-input>-->
                <el-input
                        class="mrt-10"
                        style="width: 160px;"
                        placeholder="所属订单号"
                        v-model="searchParams.fromOrder"
                        clearable>
                </el-input>
                <el-date-picker
                        class=" mrt-10"
                        style="width: 350px;"
                        v-model="searchParams.uploadDate"
                        type="datetimerange"
                        range-separator="~"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                </el-date-picker>
                <el-button type="primary" @click="onSearch">查询</el-button>
            </div>
        </div>
        <!--表格-->
        <div class="mt-3">
            <el-table
                    :data="fileData"
                    v-loading="loading"
                    align="center"
                    :element-loading-text="loadText"
                    :header-cell-style="tableHeaderColor"
                    stripe
                    style="width: 100%">
                <el-table-column
                        prop="name"
                        label="文件名称"
                        align="center"
                        >
                </el-table-column>
                <el-table-column
                        prop="apply_id"
                        label="所属订单号"
                        align="center"
                >
                </el-table-column>
                <el-table-column
                        label="上传时间"
                        align="center"
                >
                    <template slot-scope="scope">
                        <div align="center">{{scope.row['created_at']?scope.row['created_at'].slice(0, 11):'无'}}</div>
                        <div align="center">{{scope.row['created_at']?scope.row['created_at'].slice(11 ):'无'}}</div>
                    </template>
                </el-table-column>

                <el-table-column
                        label="操作"
                        fixed="right"
                        align="center"
                        width="100"
                >
                    <template slot-scope="scope">
                        <!--<el-button-->
                                <!--size="mini"-->
                                <!--type="primary"-->
                                <!--@click="handleUpload(scope.row)">下载-->
                        <!--</el-button>-->
                        <a :href="scope.row.path">下载</a>
                    </template>
                </el-table-column>
            </el-table>
            <div class="mt-3 float-right">
                <el-pagination
                        background
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageInfo.current_page"
                        :page-size="pageInfo.per_page"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageInfo.total">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "BoxList",
        data() {
            return {
                searchParams: {
                    fromOrder: '',
                    uploadDate: []
                },
                loading:false,
                loadText:'数据加载中',
                searchStr:'',
                pageInfo: {
                    per_page: 10,
                    total: 0,
                    current_page: 1,
                },
                fileData: []
            }
        },
        created() {
            this.getFileList();
        },
        methods: {
            getFileList() {
                this.loading = true;
                this.$http.get('api/admin/common/file' + this.searchStr,{
                    params: {
                        pageSize: this.pageInfo.per_page,
                        page: this.pageInfo.current_page
                    }
                })
                    .then((result)=>{
                        this.fileData = result.data;
                        this.pageInfo.total = result.meta.total;
                        this.loading = false;
                    })
                    .catch((err) => {
                        this.loading = false;
                        this.$message.warning(err.data.msg || "数据异常，请重试");
                    })
            },
            onSearch() {
                this.searchStr = "";
                if (this.searchParams.uploadDate && this.searchParams.uploadDate.length > 0) {
                    this.addConStr();
                    this.searchStr+=`created_at$=>=${this.searchParams.uploadDate[0]},<=${this.searchParams.uploadDate[1]}`;
                }
                if (this.searchParams.fromOrder) {
                    this.addConStr();
                    this.searchStr+=`apply_id=${this.searchParams.fromOrder}`;
                }
                this.pageInfo.current_page = 1;
                this.getFileList();
            },
            addConStr() {
                if (this.searchStr.length > 0) {
                    this.searchStr += '&';
                } else {
                    this.searchStr += '?';
                }
            },
            submitCostomer(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            handleSizeChange(val) {
                this.pageInfo.current_page = 1;
                this.pageInfo.per_page = val;
                this.getFileList();
            },
            handleCurrentChange(val) {
                this.pageInfo.current_page = val;
                this.getFileList();
            },
            tableHeaderColor({row, column, rowIndex, columnIndex}) {
                if (rowIndex === 0) {
                    return 'background-color: #FAFAFA;color: #000;font-weight: 500;height:54px;font-size:14px'
                }
            },
        }
    }
</script>

<style scoped>
</style>